#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon Sep 12 11:41:09 2022

@author: mac1444
"""

from scipy import optimize
import numpy as np
c=np.array([-4,-3])
a=np.array([[2,1],[1,1]])
b=np.array([10,8])
x1=[0,None]
x2=[0,7]
print(optimize.linprog(c,a,b,bounds=(x1,x2)))
#%%
import matplotlib.pyplot as plt
x=np.linspace(0,2*np.pi,100)
y1,y2=np.sin(x),np.cos(x)
plt.xlabel('x')
plt.ylabel('y')
plt.plot(x,y1)
plt.plot(x,y2)
plt.show()
#%%
from mpl_toolkits.mplot3d import Axes3D
t=np.arange(-8,8,0.25)
X,Y=np.meshgrid(t,t)
R=np.sqrt(X**2+Y**2)+np.spacing(1)
Z=np.sin(R)/R
fig=plt.figure()
ax=Axes3D(fig)
ax.plot_surface(X,Y,Z,rstride=1,cstride=1,cmap='rainbow')
plt.show()
#%%
"""
数学规划模型
scppy.optimize.linprog
"""
from scipy.optimize import linprog
import numpy as np
c=np.array([-2,-3,5])   #行列向量不影响求解
A=np.array([[-2,5,-1],[1,3,1]])
b=np.array([-10,12])
Aeq=np.array([[1,1,1]])    # 单个约束也要表示为矩阵形式
beq=np.array([7])
x=linprog(c,A,b,Aeq,beq,method='highs',bounds=np.array([[0,None],[0,None],[0,None]]))
print(x)

